// Package requests 处理登录请求数据和表单验证
package requests

import (
	"github.com/gin-gonic/gin"
	"github.com/thedevsaddam/govalidator"
)

type PermissionRequest struct {
	RoleID      string `json:"roleId,omitempty" valid:"phone"`
	Permissions string `json:"permissions,omitempty" valid:"verify_code"`
}

// LoginByPhone 验证表单，返回长度等于0即通过
func SetRolePerms(data interface{}, c *gin.Context) map[string][]string {

	rules := govalidator.MapData{
		"roleId":      []string{"required"},
		"permissions": []string{"required"},
	}

	messages := govalidator.MapData{
		"roleId": []string{
			"required:角色id为必填项，参数名称 roleId",
		},
		"permissions": []string{
			"required:permissions必填",
		},
	}

	errs := validate(data, rules, messages)
	return errs
}
